# 登录超级鹰

from selenium.webdriver import Edge
from selenium.webdriver.common.by import By
import time
import ddddocr

# http://www.chaojiying.com/


username = "tsuihxsn"  # 超级鹰用户名
password = "tsuihxsn"  # 密码

url = 'http://www.chaojiying.com/user/login'
web = Edge()
web.get(url)

time.sleep(1)  # 页面加载

# 处理验证码， 截屏保存为png图片（字节）
img = web.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/div/img').screenshot_as_png
with open('2.png', "wb")as f:
    f.write(img)
print("保存验证码成功！")

# 利用GitHub开源验证码项目识别图片
ocr = ddddocr.DdddOcr()
with open("2.png", "rb")as f:
    image_bytes = f.read()
res = ocr.classification(image_bytes)
print("验证码：", res)

# 输入用户名，密码：
el = web.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/p[1]/input')
el.send_keys(username)
ell = web.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/p[2]/input')
ell.send_keys(password)
el_code = web.find_element(By.XPATH, '/html/body/div[3]/div/div[3]/div[1]/form/p[3]/input')
el_code.send_keys(res)
time.sleep(3)

# 点击登录
web.find_element(By.XPATH, "/html/body/div[3]/div/div[3]/div[1]/form/p[4]/input").click()

time.sleep(100)
